package com.坦克大战.Tank_4;

@SuppressWarnings("all")
public class Shoot extends Thread {
    int x;
    int y;
    int direction;   ///方向
    int speed = 10;  ///子弹速度
    boolean isLive = true;  ///生命状态

    public Shoot(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    /// 子弹坐标移动线程
    @Override
    public void run() {
        while (true) {
            switch (direction) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x -= speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x += speed;
                    break;
            }
//            System.out.println("x: " + x + " y: " + y);
            if ((x >= 1600|| x <= 0 || y >= 900 || y <= 0) || !isLive) { /// 如果子弹超出了屏幕或者不存活就销毁子弹；
                System.out.println("子弹销毁");
                isLive = false;
                break;
            }

            try {
                sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }


}
